/*
 * task.h
 *
 */

#ifndef __TASK_H_
#define __TASK_H_

#ifdef  __cplusplus
extern "C" {
#endif		/* __cplusplus */

#include "stm32f10x.h"
/** @name TASK ERROR CODE DEFINE
 * @{
 */
#define TASK_OK					0	///< Success
#define TASK_ERR_BUF_FULL		1	///< task buffer full
#define TASK_ERR_ALREADY_IN		2	///< task has added
#define TASK_ERR_NOT_FOUND		3	///< task not found
  
#define SUPER_TASK_NUM		2	///< max number of supertask
#define TASK_NUM			50	///< max number of task
/** @} */

extern void TaskInit(void);
extern int TaskAdd(void (*fun)(void), unsigned short loop_time);
extern int TaskDel(void (*fun)(void));
extern void TaskSch(void);
extern int TaskGetIdx(void (*fun)(void));
extern int SuperTaskAdd(void (*fun)(void));
extern int SuperTaskDel(void (*fun)(void));
extern void TaskRun(void);

/** @brief use to entry critical section */
#define ENTRY_CRITICAL_SECTION()	__disable_irq()
/** @brief use to exit critical section */
#define EXIT_CRITICAL_SECTION()		__enable_irq()

#ifdef __cplusplus
}
#endif	/* __cplusplus */
#endif	/* __TASK_H_ */
/** @} */